A Taste of Agent-Based Modelling

Bo Yang Tang

Why ABMs interest me

  • Computer Science background
  • I like to code
  • I like to think about social issues

Psychology is complicated

e.g. Communal motivation involves

  • Cultural continuity
  • Ostracism
  • Social embeddedness
  • Social capital
  • Commitment mechanisms
  • Social media
  • Identity fusion
  • ………

Psychology is complicated

  • How do we combine ideas?
  • Which effects are dominant?
  • Generalizability

Motivation

  • Replication crisis
  • Social scientists make poor real world predictions (Grossmann et al. 2024)
  • Is human behaviour too complicated for our toolkit?

Figure 1: Obstacles to accurate predictions (Grossmann et al. 2024)

Where ABMs Can Help

  • Combining theories
  • Flexible Analyses
  • High fidelity
  • Personal development?

Parts of an Agent-based Model

Environment

  • Network
  • Discrete grid
  • Continuous space

Agents

Time Step

Parts of an Agent-based Model

Time 0

  • Generate environment
  • Generate agents and place them in the environment

Time 1, 2, 3, …, Stop

  • Agents activate
  • The environment can change

What to model?

Evolution

  • Simple premise
  • Constant thread through theories

Implementing a simple idea

  • What is an obvious evolutionary relationship?
  • How can we show this using agents?

flowchart LR
  A["Fitness"] --> B["Prevalence"]

Software

How does fitness relate to prevalence?

  • Each agent has a fitness value
  • This fitness value has to affect the agent’s reproduction

How does fitness relate to prevalence?

class Agent:
  self.fitness

  reproduce():
    self.fitness -> probability of success

  step():
    reproduce()

Is simplicity the goal?

My first implementation

class Agent:
  self.fitness
  self.energy

  feed():
    self.fitness -> probability of +2 energy

  reproduce():
    always successful
  
  metabolism():
    self.energy - 1
  
  step():
    metabolism()
    reproduce()
    if self.energy < 0 then remove agent
    else feed()

References

Grossmann, Igor, Michael E. W. Varnum, Cendri A. Hutcherson, and David R. Mandel. 2024. “When Expert Predictions Fail.” Trends in Cognitive Sciences 28 (2): 113–23. https://doi.org/10.1016/j.tics.2023.10.005.
McKinney, Wes. 2010. “Data Structures for Statistical Computing in Python.” In, 56–61. Austin, Texas. https://doi.org/10.25080/Majora-92bf1922-00a.
Satyanarayan, Arvind, Dominik Moritz, Kanit Wongsuphasawat, and Jeffrey Heer. 2017. “Vega-Lite: A Grammar of Interactive Graphics.” IEEE Transactions on Visualization and Computer Graphics 23 (1): 341–50. https://doi.org/10.1109/TVCG.2016.2599030.
team, The pandas development. 2025. “Pandas-Dev/Pandas: Pandas.” Zenodo. https://doi.org/10.5281/ZENODO.16918803.
Ter Hoeven, Ewout, Jan Kwakkel, Vincent Hess, Thomas Pike, Boyu Wang, Rht, and Jackie Kazil. 2025. “Mesa 3: Agent-based Modeling with Python in 2025.” Journal of Open Source Software 10 (107): 7668. https://doi.org/10.21105/joss.07668.
VanderPlas, Jacob, Brian Granger, Jeffrey Heer, Dominik Moritz, Kanit Wongsuphasawat, Arvind Satyanarayan, Eitan Lees, Ilia Timofeev, Ben Welsh, and Scott Sievert. 2018. “Altair: Interactive Statistical Visualizations for Python.” Journal of Open Source Software 3 (32): 1057. https://doi.org/10.21105/joss.01057.
Waskom, Michael. 2021. “Seaborn: Statistical Data Visualization.” Journal of Open Source Software 6 (60): 3021. https://doi.org/10.21105/joss.03021.